import redis
import random
import string
#定义ip和端口  
host = "localhost"
port = 6379

#建立链接
r = redis.Redis(host=host,port=port)



words = random.sample(string.digits+string.ascii_letters,6)
words = "".join(words)

code = r.set('code',words)
# r.expire('code',5)
print(code)
# print(r)
code = r.get('code')
# code = code.decode("utf-8")


print(code)